package it.blueocean.acanto.taglibrary.jsp.taglib.tags.common;

import it.blueocean.acanto.taglibrary.jsp.taglib.tags.dataset.ConditionalTag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

public class ConditionTrueTag extends BodyTagSupport
{
	private static final long serialVersionUID = 6516365210088854059L;

	public int doStartTag() throws JspException
	{
		Tag localTag = findAncestorWithClass(this, ConditionalTag.class);
		
		if(localTag == null)
		{
			throw new JspException("ConditionFalseTag can only be used inside a ConditionalTag");
		}
		
		ConditionalTag localConditionalTag = (ConditionalTag) localTag;
		
		if(localConditionalTag.isConditionTrue())
		{
			return 1;
		}
		
		return 0;
	}

}